package com.sky.controller;


import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 菜品管理
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {
    @Resource
    DishService dishService;

    /**
     * 新增菜品
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO){   //返回一个成功的结果即可 不需要返回数据
        log.info("新增菜品：{}", dishDTO);
        dishService.saveDish(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页查询
     * @param dishDTO
     * @return
     */
    @ApiOperation("菜品分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishDTO){
        log.info("菜品分页查询：{}", dishDTO);
        PageResult page = dishService.page(dishDTO);
        return Result.success(page);
    }

    @ApiOperation("菜品批量删除")
    @DeleteMapping
    public Result deleteById(@RequestParam("ids") Long[] ids){
        log.info("菜品批量删除：{}", ids);
        dishService.deleteById(ids);
        return Result.success();
    }

}
